package com.kun.portal.webframe.util;

import com.kun.portal.webframe.po.CourseNodePo;
import com.kun.portal.webframe.po.FwUserPo;
import com.kun.portal.webframe.po.MessagePushPo;
import com.kun.portal.webframe.service.MessagePushService;
import com.kun.portal.webframe.util.MessageFormatImp.AddAppointment;
import com.kun.portal.webframe.util.eventQuene.EventProcessor;
import com.kun.portal.webframe.util.eventQuene.Message;

import java.util.Date;
import java.util.List;

public class MessageEmit {
    public static void emit(FwUserPo publishPerson, MessageFormat messageFormat, String eventType,  MessagePushService messagePushService){
        MessagePushPo messagePushPo = new MessagePushPo();
        messagePushPo.setPushTime(new Date());
        messagePushPo.setPushUser(publishPerson);
        messagePushPo.setMgType(eventType);
        messagePushPo.setMgContent(messageFormat.getMessageContext());
        List<String> list = MessageFilter.getMessageType(eventType);
        for(String messageType :list){
            messagePushPo.setModuleType(messageType);
            messagePushService.saveMp(messagePushPo);
            EventProcessor.publish(new Message(messageType,eventType,messagePushPo));
        }
    }

    public static void emit(CourseNodePo courseNodePo, String eventType){

        List<String> list = MessageFilter.getMessageType(eventType);
        for(String messageType :list){

            EventProcessor.publish(new Message(messageType,eventType,courseNodePo));
        }
    }
    public static void emit(Object object, String eventType){

        List<String> list = MessageFilter.getMessageType(eventType);
        for(String messageType :list){
            EventProcessor.publish(new Message(messageType,eventType,object));
        }
    }
}
